/*Keeps and maintains the humidity data for the simulation*/
public class HumidMap
{
static int[][]  hmap;//internal repesentation of the humidity map

public static int[][] GetHumidData()
{//return raw humidity map for the renderer
  return hmap;
}
public static void SetHumidData(int[][] map) {
  hmap = map;
}
public static void ModifyHumid(loc[][] wmap)
{
  Magic_Eight_Ball.prove_HumidMap_Updates(); //This code is for testing purposes
 //As wind increases remove more of the local humidity, approaching 50%
 int[][] chmap = new int[SimulationConstants.simsize][SimulationConstants.simsize];
 int map[][] = HeightMap.GetHeightMap();
    for(int x=0; x<SimulationConstants.simsize; x++)
    {
      for(int y=0; y<SimulationConstants.simsize; y++)
      {
        chmap[x][y]=0;
      }
    }
    for(int x=0; x<SimulationConstants.simsize; x++)
    {
      for(int y=0; y<SimulationConstants.simsize; y++)
      {
        int newx = (x + wmap[x][y].x)%SimulationConstants.simsize;
        int newy = (y + wmap[x][y].y)%SimulationConstants.simsize;
        if(newx<0)
          newx+=SimulationConstants.simsize;
        if(newy<0)
          newy+=SimulationConstants.simsize;
        double amount = Math.pow(((double) wmap[x][y].x*wmap[x][y].x + wmap[x][y].y*wmap[x][y].y),-0.5);
        int pulled = hmap[x][y]/2;
        hmap[x][y]-=pulled;
        chmap[newx][newy]+=pulled;
      }
    }
    double averagetemp =0.0;//debug
    for(int x=0; x<SimulationConstants.simsize; x++)
    {
      for(int y=0; y<SimulationConstants.simsize; y++)
      {
        hmap[x][y]+=chmap[x][y];
        {
          if(map[x][y]<=SimulationConstants.sealevel)
          {
            hmap[x][y]+=SimulationConstants.humidity*2-5;//if in sea then add to humidity
          }
          else //negative humidty was a silly idea
          {
            hmap[x][y]-=(5-SimulationConstants.humidity/2);////if not in sea then subtract from humidity
          }
          if(map[x][y]<0)
             map[x][y]=0;  //I repeat: negative humidty was a silly idea
        }
      }
    }
    //////System.out.println(averagetemp/(SimulationConstants.simsize.0*SimulationConstants.simsize.0));//debug
}
  

  
public static void SeismicHumid(loc s)
  {
   //set Humidity due to seismic event 
  int map[][] = HeightMap.GetHeightMap();
  for(int r1=-3; r1<=3; r1++)
   {
     for(int r2=-3; r2<=3; r2++)
     {
       if(map[((s.x+r1)%512<0)?(512+(s.x+r1)%512):(s.x+r1)%512][((s.y+r2)%512<0)?(512+(s.y+r2)%512):(s.y+r2)%512]<=SimulationConstants.sealevel)
         hmap[((s.x+r1)%512<0)?(512+(s.x+r1)%512):(s.x+r1)%512][((s.y+r2)%512<0)?(512+(s.y+r2)%512):(s.y+r2)%512]=10000;//The trinary operators deal with wrapping around the left and bottom edges
     }
   }
    
  }
public static void initalize()
{
  hmap = new int[SimulationConstants.simsize][SimulationConstants.simsize];
  int map[][] = HeightMap.GetHeightMap();
 for(int x=0;x<SimulationConstants.simsize;x++)
 {
  for(int y=0;y<SimulationConstants.simsize;y++)
  {
   if(map[x][y]<=SimulationConstants.sealevel)
   {
    hmap[x][y]=100;//if in sea then 100 humidity 
   }
   else
   {
     int t = 100-(map[x][y]-SimulationConstants.sealevel);//temporary variable to hold to make sure there is no negative humidity
     if(t>0)//check for negative humidity
       hmap[x][y]=t;
     else
       hmap[x][y]=0;//if negative then it is just 0 humidity
   }
  }
   
 }
 TempMap.Initalize();
 PlantMap.Initalize();
 WindMap.initalize();
}
  
  
  
}